package com.xjh.serverinspect.util;

import lombok.Getter;
import lombok.Setter;

/**
 * <p>
 * 响应DTO
 * </p>
 *
 * @author xujinghui
 * @since 2024-12-12
 */
@Getter
@Setter
public class ResponseDTO {

    private Integer code;

    private String message;

    private Object data;

    private ResponseDTO(Integer code, String message, Object data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    private ResponseDTO(ResponseCodeEnum code, Object data) {
        this(code.getCode(), code.getMessage(), data);
    }

    public static ResponseDTO success(Object data) {
        return new ResponseDTO(ResponseCodeEnum.SUCCESS, data);
    }

    public static ResponseDTO success() {
        return success(null);
    }

    public static ResponseDTO error(ResponseCodeEnum code, String message) {
        return new ResponseDTO(code.getCode(), message, null);
    }

    public static ResponseDTO error(ResponseCodeEnum code) {
        return new ResponseDTO(code, null);
    }

}
